from django.contrib.auth.models import User
from django.db import models



# Create your models here.

class Classes(models.Model):
    id = models.AutoField(primary_key=True)  # 主键有默认唯一约束，Django可以不额外设置，会自动帮创建
    name = models.CharField(max_length=30, unique=True)
    def __str__(self):
        return self.name

class Label(models.Model):
    name = models.CharField(max_length=30, unique=True)
    def __str__(self):
        return self.name

class Userdetail(models.Model):
    age=models.IntegerField(null=True,blank=True)
    sex=models.BooleanField(null=True,blank=True)
    user=models.OneToOneField(User,on_delete=models.CASCADE)

class Article(models.Model):
    title=models.CharField(max_length=30)
    desc=models.CharField(max_length=200)
    content=models.TextField()
    cover=models.TextField()
    create_time=models.DateTimeField(auto_now_add=True)
    update_time=models.DateTimeField(auto_now=True)
    user=models.ForeignKey(User,on_delete=models.CASCADE)
    classes=models.ForeignKey(Classes,on_delete=models.NOT_PROVIDED)
    label=models.ManyToManyField(Label)
    def __str__(self):
        return self.title